class Solution {
public:
	vector<vector<int>> generateMatrix(int n) {

		vector<vector<int>> vv(n, vector<int>(n, 0));
		int startx = 0;
		int starty = 0;
		int mid = n / 2;
		int loop = n / 2;
		int count = 1;
		int offset = 1;

		while (loop--){
			int i = startx;
			int j = starty;

			for (j = starty; j<starty + n - offset; j++){
				vv[i][j] = count++;
			}
			for (i = startx; i<startx + n - offset; i++){
				vv[i][j] = count++;
			}
			for (; j>starty; j--){
				vv[i][j] = count++;
			}
			for (; i>startx; i--){
				vv[i][j] = count++;
			}
			startx++;
			starty++;

			offset += 2;

		}


		if (n % 2){
			vv[mid][mid] = n*n;
		}
		return vv;



	}
};